home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Language/OS - Multiplatform Resource Library
/
LANGUAGE OS.iso
/
cpp_libs
/
perlcl16.lha
/
perlclass1.6
/
perlclass.doc
< prev
next >
Wrap
Text File
|
1992-11-10
|
11KB
|
315 lines
class PerlList<T> - A list of any type specified by T
T& operator[n] - returns a reference to the element at index
'n' (0 based). Generates an ASSERT error
if n < 0, can be used as an lvalue. Using
an index greater than the current size of the
list will cause the list to grow upto that
index. The values inbetween will be undefined
if <T> is a built-in type.
operator void*() - returns NULL if the list is empty,
can be used like: if(list) // not empty
int isempty() - returns TRUE if the list is empty, as an
alternative for the previous technique
void reset() - clears all elements in the list, but doesn't
actually free up the storage until it is
destroyed
int scalar() - returns the number of elements in the list
T pop() - removes and returns the last element on the
list. If the list is empty the value returned
is usually undefined
void push(T x) - puts the single value 'x' at the end of the
list
void push(PerlList<T> l)
- puts all the elements in the list 'l' at the
end of the list.
T shift() - removes and returns the first element
in the list
int unshift(T x) - puts the single value 'x' at the start
of the list
int unshift(PerlList<T> l)
- puts all the elements in the list 'l'
at the start of the list
PerlList<T> reverse()
- returns a list that is in the reverse
order
PerlList<T> splice(offset, len, PerlList<T> l)
- removes 'len' elements from 'offset' (0 based)
and inserts all the elements in the list 'l'
at the same position
PerlList<T> splice(offset, len)
- removes 'len' elements from 'offset' (0 based)
PerlList<T> splice(offset)
- removes all the elements from 'offset'
(0 based)
PerlList<T> sort() - returns a list that has been sorted according
to the rules that T::operator<() returns
for the type T.
class PerlStringList - everything PerlList does and ...
int split(str [,pat] [,limit])
- appends the results of splitting the string
'str' to the list. If 'pat' is specified then
any string that matches the RE 'pat' is
considered a separator to split on, the
default is white-space. If 'limit' is specified
then no more than that number of elements is
generated. If 'limit' is not specified, then empty
entries are stripped from the end of the list.
If the RE includes subexpressions then they
are inserted into the list as well.
If 'pat' is equal to the string "' '" then
a special case is done which matches awks
handling of whitespace. If 'pat' is an empty
string "", then all characters are split into
the list
PerlString join([pat])
- Returns the string that is the result of
combining all the elements in the list, and
separating them by 'pat'. If 'pat' is omitted
then the elements are separated by a space
int m(const char *exp, targ [,opts)
- Appends to the list all the subexpression
matches that occured when applying the regular
expression 'exp' to the string 'targ'.
The number of matches is returned. The first
element generated is the entire matched string
opts: (a const char * with default "")
i - Forces case insensitive match
PerlStringList grep(const char *exp [,opts])
- returns a list of all the elements that
matched the regular expression 'exp'.
opts: (a const char * with default "")
i - Forces the search to be case insensitive
class PerlString - A standard c null-terminated string may be
used anywhere that a perl string can be used
and vice-versa.
- Individual characters may be read with
the '[]' operator (unlike perl).
int length() - returns the length of the string
char chop() - removes and returns the last character in the
string
int index(PerlString str [, offset])
- returns the offset in the string that matches
the string 'str', starting at position
'offset' if specified, otherwise searches the
entire string.
Returns -1 if no match is found
int rindex(PerlString str [, offset])
- returns the offset in the string that matches
the string 'str', starting at the end of the
string - 'offset' if specified, otherwise
searches the entire string.
Returns -1 if no match is found
substring substr(offset [, len])
- returns the substring within the string that
starts at 'offset' and is 'len' characters, if
'len' is omitted the rest of the string is
returned.
This may be used as an lvalue, in which case
the characters are removed, and the RHS of the
expression in inserted at the same postion.
PerlStringList split([,pat] [,limit])
- same as PerlStringList::split() but returns
a list of splits
operator< - These operators do what you would expect
operator>
operator<=
operator>=
operator==
operator!=
operator+ - returns the result of contenating two or more
strings
operator+= - replaces the LHS of the expression with the
concatenation of the LHS with the RHS
int m(const char *exp [,opts])
- returns 0 if the regular expression 'exp'
fails to match the string. Returns 1 if a
match was made
opts: (a const char * with default "")
i - Forces case insensitive match
int m(const Regexp& exp)
- Same as above but takes a precompiled
regular expression.
int m(const char *exp, PerlStringList& l [,opts])
- Loads the list 'l' with all subexpression
matches of the regular expression 'exp' with
the string. Returns 0 if no matches were made.
Returns the number of matches if any
opts: (a const char * with default "")
i - Forces case insensitive match
int m(const Regexp& exp, PerlStringList& l)
- Same as above but takes a precompiled
regular expression.
int tr(search, repl [,opts])
- replaces all occurrences of characters in 'search'
with the equivalent character in 'repl'. If 'repl'
is empty then just counts the characters.
opts: (a const char *) default is ""
c - complements the 'search' pattern. Replaces
all characters that are not in 'search', with
the last character specified in 'repl'.
d - deletes characters in 'search' that don't have an
equivalent 'repl'
cd - deletes characters not in 'search'
s - compresses sequences of translated characters
in resulting string
int s(exp, repl [,opts])
- substitute the first substring matched by
'exp' with the string 'repl'. $& in 'repl'
will be replaced by the entire matching
string, $1 - $9 will be replaced by the
respective subexpression match. \$ or \\
will insert a $ or \ respectively.
opts: (a const char *) default is ""
g - causes all occurrences of 'exp' in
the string to be replaced by 'repl'
i - Forces case insensitive matching
class Assoc<T> - an associative array whose key is a PerlString
and the value is any type T
Assoc(PerlString defkey, T defvalue)
- Constructor for an associative array, 'defkey'
becomes the default key, and 'defvalue' is the
default value. The default value is used to
create a new Association if a key is specified
that doesn't yet exist.
T& operator(PerlString str)
- returns a reference to the value that is
associated with the key 'str'. This may be
used as an lvalue, and is in the only way to
make an association. If the key didn't exist
it will be entered with the default value, if
it was specified in the constructor, and a
reference to that is returned. If no default
was specified, then the value will be
undefined
Binar& operator[n] - Returns the (key, value) pair found at index
'n' of the associative array
PerlStringList keys()
- Returns a list of all the keys in the
associative array.
PerlList<T> values()
- Returns a list of all the values in the
associative array.
int isin(PerlString key)
- Returns 1 if the string 'key' is a valid key
in the associative array. Returns 0 otherwise.
T adelete(PerlString key)
- deletes the entry whose key matches the string
'key'. The value of the deleted entry is
returned. Nothing happens if the key is not
found.
Miscellaneous
=============
class Range - stores the range used in Regexp
Range(s, e) - creates a range whose start is at position
's' and the last character in the range is at
position 'e'. (inclusive range)
int start() - returns the start of the range
int end() - returns the end of the range (the position
of the last character in the range).
int length() - returns the length of the range.
class Regexp - Henry Spencers regular expression package
oo-ized
Regexp(exp [,opts]) - Compiles a regular expression that can be
passed to one of the m() functions.
opts: (an int with default 0)
Regexp::nocase - Forces case insensitive
match
int match(targ) - returns 1 if the compield RE matches 'targ'
returns 0 if not
int groups() - returns 1 + the number of subexpression
matches found in the last match(). If the
previous match() succeeded then the whole
match is included in the count (hence +1)
Range getgroup(n) - returns the range of the 'n'th subgroup.
'n' = 0 is the range of the entire match
PerlStringList m(exp, targ [,opts])
- returns a list of all the subexpression
matches that occured when applying the
regular expression 'exp' to the string
'targ'. element 0 of the list is the first
subexpression, element 1 the next, etc.
opts: (a const char * with default "")
i - Forces case insensitive match
xin >> aperlstring
- Text from the stream xin is loaded into
aperlstring, the text is expected to be
terminated by '\n', which is removed from
the stream, but not put into aperlstring.
aperlsring is cleared first.
xin >> aperlstringlist
- Each Text line, as defined above, is loaded
into an element of aperlstringlist, which
is reset first.
To pre-compile a regular expression use Regexp(const char *, iflg).
eg
Regexp rexp("...([a-z*)$");
//Regexp rexp("...([a-z*)$", Regexp::nocase); // for case insensitive
PerlString s;
for(int i=0;i<large_number;i++){
... load s with string ...
if(s.m(rexp)) ... do something when matched
}